package com.ruoyi.project.yuwen.yuwenaudio.service.impl;

import com.ruoyi.common.utils.CacheUtil;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.yuwen.yuwenaudio.domain.Audio;
import com.ruoyi.project.yuwen.yuwenaudio.mapper.AudioMapper;
import com.ruoyi.project.yuwen.yuwenaudio.service.IAudioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课文朗读Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-02-24
 */
@Service
@DataSource(DataSourceType.KKCUSER)
public class AudioServiceImpl implements IAudioService {

    @Autowired
    private AudioMapper audioMapper;

    /**
     * 查询课文朗读
     *
     * @param vid 课文朗读ID
     * @return 课文朗读
     */
    @Override
    public Audio selectAudioById(String vid) {
        return audioMapper.selectAudioById(vid);
    }

    /**
     * 查询课文朗读列表
     *
     * @param audio 课文朗读
     * @return 课文朗读
     */
    @Override
    public List<Audio> selectAudioList(Audio audio) {
        return audioMapper.selectAudioList(audio);
    }

    /**
     * 新增课文朗读
     *
     * @param audio 课文朗读
     * @return 结果
     */
    @Override
    public int insertAudio(Audio audio) {
        return audioMapper.insertAudio(audio);
    }

    /**
     * 修改课文朗读
     *
     * @param audio 课文朗读
     * @return 结果
     */
    @Override
    public int updateAudio(Audio audio) {
        return audioMapper.updateAudio(audio);
    }

    /**
     * 删除课文朗读对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAudioByIds(String ids) {
        return audioMapper.deleteAudioByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课文朗读信息
     *
     * @param vid 课文朗读ID
     * @return 结果
     */
    @Override
    public int deleteAudioById(String vid) {
        return audioMapper.deleteAudioById(vid);
    }

    @Override
    public int updateStatus(String vid, Integer vstatus) {

        Audio audio = audioMapper.selectAudioById(vid);
        audio.setVstatus(vstatus);
        audio.setChecker(ShiroUtils.getLoginName());
        int ret = audioMapper.updateAudio(audio);
        if (ret > 0) {
            //删除缓存
            CacheUtil.delete("kkyuwen", "k:w:a:" + audio.getKewenid());
        }
        return ret;
    }
}
